package editro.view.components 
{
	import editro.model.AntTaskVOListModel;
	import editro.model.ATEConfigModel;
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.geom.Point;
	import org.osflash.signals.Signal;
	
	/**
	 * ...
	 * @author LEEF LEE_LEAF918@163.COM_QQ969442267
	 */
	public class ArchorLinkLineOverlay extends Sprite 
	{
		private var _lineColor:uint;
		private var _lineThickness:uint;
		private var floatStartPoint:Point;
		private var isOnFloatingDrawing:Boolean;
		private var cursorPoint:Point;
		private var linkLineArr:Array = [];
		public var updateLinkArraySignal:Signal;
		public function ArchorLinkLineOverlay() 
		{
			//基本属性
			this.mouseEnabled = false;
			updateLinkArraySignal = new Signal(Array);
		}
		/**
		 * 刷新所有关系连线
		 */
		public function refresh():void 
		{
			/**
			 * 更新连线数组
			 */
			linkLineArr = [];
			updateLinkArraySignal.dispatch(linkLineArr);
			this.graphics.clear();
			for (var i:int = 0; i < linkLineArr.length; i++) 
			{
				var item:Array = linkLineArr[i];
				drawLinkLine(this.graphics, item[0],item[1]);
			}
		}
		
		public function begainDrawFloatingLine(pnt:Point):void 
		{
			this.floatStartPoint = pnt;
			isOnFloatingDrawing = true;
		}
		/**
		 * 不断记录场景的鼠标坐标更新，鼠标一动就会更新，非常频繁
		 * @param	pnt
		 */
		public function updateStageCursorPoint(pnt:Point):void 
		{
			this.cursorPoint = pnt;
			if (isOnFloatingDrawing) {
				drawLinkLine(graphics, floatStartPoint, cursorPoint);
			}
		}
		
		public function cancleFloat():void 
		{
			isOnFloatingDrawing = false;
		}
		
		/**
		 * 算法比较简单，算出两点中心点，再算出以中心点对称的控制点
		 * @param	gr
		 * @param	stPoint
		 * @param	edPoint
		 */
		private function drawLinkLine(gr:Graphics,stPoint:Point,edPoint:Point):void 
		{
			//gr.clear();
			//计算两点中点
			var midP:Point = Point.interpolate(stPoint, edPoint, .5);
			var startControlPoint:Point = stPoint.clone();
			startControlPoint.offset(midP.x - stPoint.x, 0);
			var endControlPoint:Point = edPoint.clone();
			endControlPoint.offset(midP.x - edPoint.x, 0);
			//
			gr.lineStyle(_lineThickness,_lineColor);
			gr.moveTo(stPoint.x, stPoint.y);
			gr.curveTo(startControlPoint.x, startControlPoint.y, midP.x, midP.y);
			gr.curveTo(endControlPoint.x, endControlPoint.y, edPoint.x, edPoint.y);
			//
		}
		
		public function set lineColor(value:uint):void 
		{
			_lineColor = value;
		}
		
		public function set lineThickness(value:uint):void 
		{
			_lineThickness = value;
		}
	}

}